package com.xzssmk.leisure.x.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xzssmk.leisure.x.po.PeriodSpot;
import com.xzssmk.leisure.x.service.PeriodSpotService;
import com.xzssmk.leisure.x.util.DataTables;

@RestController
@RequestMapping("issuePeriodScenicSpot")
public class IssuePeriodScenicSpotController {

    @Autowired
    PeriodSpotService periodSpotService;

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String add(PeriodSpot periodSpot) {
        periodSpot.setCreateTime(new Date());
        return JSONObject.toJSONString(periodSpotService.add(periodSpot));
    }

    @RequestMapping(value = "/getPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getPageList(HttpServletRequest request, String issuePeriodId) {
        return JSONObject
            .toJSONString(periodSpotService.getPageList(DataTables.getInstance(request, null), issuePeriodId));
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public Object delete(@RequestParam("idlist[]") List<Integer> idlist) {
        return JSONObject.toJSONString(periodSpotService.delete(idlist));
    }

    @RequestMapping(value = "/issuePeriod-scenicSpot-list.html")
    public ModelAndView IssuePeriodScenicSpot() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("issuePeriod-scenicSpot-list");
        return modelAndView;
    }
}
